def ftreat(lines):
    lines2=[]
    for line in lines:
        if '!' in line and line.index('!')>0:
            line=line[0:line.index('!')]
            line+='\n'
        lines2.append(line)
    return lines2

def ffilter(lines):
    return any(map(lambda x:'!' in x and x.index('!')>0, lines))



import glob

ff=glob.glob('*.f')

for f in ff:
    print f
    aa=open(f,'r')
    lines=aa.readlines()
    aa.close()
    if ffilter(lines):
        aa=open(f,'w')
        lines2=ftreat(lines)
        aa.writelines(lines2)
        aa.close()